package com.example.blew.demo.Controller;

import cn.hutool.core.util.ObjectUtil;
import com.example.blew.omp.system.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/8/18
 */


@RestController
@RequestMapping("Redis")
@Api(tags = "redis测试接口",value = "redis测试接口")
public class TestRedis {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    RedisUtil redisUtil;


    @ApiOperation(value = "redis读接口")
    @PostMapping("TestRedis")
    public String fun(String key) {
//        Object name = redisTemplate.opsForValue().get(key);
        Object name = redisUtil.read(key);
        if(!ObjectUtil.isNotNull(name))
        {
            return "不存在";
        }
        return (String) name;
    }

    @ApiOperation(value = "redis写接口")
    @PostMapping("redisWrite")
    public String fun2(String str) {
//        RedisUtil redisUtil=new RedisUtil();
        String key="TestKey";
        redisUtil.basisClassSaveObj(str,redisTemplate,key);
        return "ok";
    }


}